package server;

import common.XmlConstants;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;


/*
 * This file is part of shared-drawing.
 * shared-drawing is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option )
 * any later version. shared-drawing is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 * You should have received a copy of the GNU General Public License along with 
 * shared-drawing. If not, seehttp://www.gnu.org/licenses/.
*/

class XmlReaderServerConnection implements ContentHandler {

    private ClientThread client;
    
    public XmlReaderServerConnection(ClientThread client_thread) {
        client = client_thread;
    }
    
    @Override
    public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributes) throws SAXException {
        if(!"join".equals(localName))
        {
            System.out.println("the user must join before doing anything else");
            return;
        }
        String nick_name = attributes.getValue(XmlConstants.emitterNickName);
        String work_group_name = attributes.getValue(XmlConstants.workgroupName);
        String pass_word = attributes.getValue(XmlConstants.workgroupPassword);
        client.connectMe(nick_name, pass_word, work_group_name);
        System.out.println("[Client] " + nick_name + " tries to connect on " + work_group_name + ".");
    }
    
    @Override
    public void setDocumentLocator(Locator lctr) {
    }

    @Override
    public void startDocument() throws SAXException {
    }

    @Override
    public void endDocument() throws SAXException {
    }

    @Override
    public void startPrefixMapping(String string, String string1) throws SAXException {
    }

    @Override
    public void endPrefixMapping(String string) throws SAXException {
    }

    @Override
    public void endElement(String string, String string1, String string2) throws SAXException {
    }

    @Override
    public void characters(char[] chars, int i, int i1) throws SAXException {
    }

    @Override
    public void ignorableWhitespace(char[] chars, int i, int i1) throws SAXException {
    }

    @Override
    public void processingInstruction(String string, String string1) throws SAXException {
    }

    @Override
    public void skippedEntity(String string) throws SAXException {
    }

}
